<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%@ page import="com.ai.core.util.Configure"%>
<%@ page import="com.ai.wx.util.WeixinUtil"%>
<%@ page import="com.ai.wx.entity.AgentUser"%>
<%@ page import="com.ai.core.constant.GlobalConstant"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>推广员审核</title>
<link media="all" href="${ctx}/css/box.css" rel="stylesheet">
<link media="all" href="${ctx}/css/style.css" rel="stylesheet">

<script type="text/javascript" src="${ctx}/js/jquery.min.js"></script>
<script type="text/javascript" src="${ctx}/js/common.js"></script>
<script src="${ctx}/js/handlebars-v2.0.0.js"></script>


</head>
<body>
<div class="wrap">
  <div class="head">
    <div>| 流量超市后台管理系统</div>
  </div>
  <div class="out-content">
    <div class="user">
      <div class="user-text">
        <p>下午好，管理员</p>
        <p><span>账户名 : admin</span><span>上次登录时间 ： 2015-05-14</span></p>
      </div> 
    </div>
    <div class="ui-nav ui-nav-nosub">
      <ul class="ui-nav-main">
        <li class="ui-nav-item ui-nav-item-current"> <a href="${ctx}/ht/agentUserApprove">推广员审核</a> </li>
        <li class="ui-nav-item "> <a href="${ctx}/ht/brokerageDrawApprove">推广金提取审核</a> </li>
      </ul>
      <div class="ui-nav-subcontainer"></div>
    </div>
    <div class="ui-table-container">
      <table class="ui-table recharge">
        <!-- 可以在class中加入ui-table-inbox或ui-table-noborder分别适应不同的情况 -->
        <thead>
          <tr>
            <th width="120px">日期</th>
            <th width="100px">姓名</th>
            <th width="150px">身份证号码</th>
            <th width="100px">手机</th>
            <th width="60px">状态</th>
            <th>不批准理由</th>
            <th width="80px">详情</th>
          </tr>
        </thead>
        <!-- 表头可选 -->
        <tbody id="tableData"> 
        </tbody>
        <tfoot>
          <tr>
            <td colspan="7"  id="paging">
               
            </td>
          </tr>
        </tfoot>
        <!-- 表尾可选 -->
      </table>
    </div>
  </div>
</div>
<div class="foot">
  <p></p>
</div>

<!-- 弹窗 -->
<div id="open-window"></div>
<!-- 点击日志图片放大 -->
<div style="overflow:auto;position: fixed;  top: 0px; left: 0px; background: none repeat scroll 0% 0% rgba(0, 0, 0, 0.7); z-index:999999; width: 100%; height: 100%; display: none;" id="outerdiv">
    <div style="position: absolute; top: 63.1px; left: 270.66px;" id="innerdiv">
       <img src="" style="border: 5px solid rgb(255, 255, 255); width: 807.68px;" id="bigimg">
    </div>
</div>

<script id="agentUserList" type="text/x-handlebars-template">
   {{#each this}}
          <tr {{trClass @index}}>
            <td>{{crtDate}}</td>
            <td>{{userName}}</td>
            <td>{{idCard}}</td>
            <td>{{phone}}</td>
            <td>{{agentStateStr agentState}}</td>
            <td>{{reason}}</td>
            <td><a href="javascript:;" class="ui-button ui-button-swhite" onClick="openWin({{id}})">审核</a></td>
          </tr> 
   {{/each}}
</script>

<script id="agentUserInfo" type="text/x-handlebars-template">
   {{#each this}}  
  <div id="overlay"></div>
  <div id="dialog">
    <div class="dialog-body">
      <div class="ui-box window">
        <div class="ui-box-head">
          <h3 class="ui-box-head-title">推广员审批</h3>
          <a href="#" class="ui-box-head-more" onClick="closeWin()"><em>×</em></a> </div>
        <div class="ui-box-container">
          <div class="ui-box-content">
            <dl class="ui-dlist">
              <dt class="ui-dlist-tit">姓名：</dt>
              <dd class="ui-dlist-det">{{userName}}</dd>
              <dt class="ui-dlist-tit">身份证号码：</dt>
              <dd class="ui-dlist-det">{{idCard}}</dd>
              <dt class="ui-dlist-tit">身份证正面：</dt>
              <dd class="ui-dlist-det"><img src="${ctx}/ht/image/{{idCardPicF}}" height="80px"> <a title="查看大图" href="javascript:;" class="idCardImg" data-src="${ctx}/ht/image/{{idCardPicF}}">查看大图</a></dd>
              <dt class="ui-dlist-tit">身份证反面：</dt>
              <dd class="ui-dlist-det"><img src="${ctx}/ht/image/{{idCardPicB}}" height="80px"> <a title="查看大图" href="javascript:;" class="idCardImg" data-src="${ctx}/ht/image/{{idCardPicB}}">查看大图</a></dd>
              <dt class="ui-dlist-tit">手机号码：</dt>
              <dd class="ui-dlist-det">{{phone}}</dd>
              <dt class="ui-dlist-tit">邮箱：</dt>
              <dd class="ui-dlist-det">{{email}}</dd>
              <dt class="ui-dlist-tit">开户银行：</dt>
              <dd class="ui-dlist-det">{{bankName}}</dd>
              <dt class="ui-dlist-tit">银行卡号</dt>
              <dd class="ui-dlist-det">{{bankCard}}</dd>
              <dt class="ui-dlist-tit">日期：</dt>
              <dd class="ui-dlist-det">{{crtDate}}</dd>
              <dt class="ui-dlist-tit">状态：</dt>
              <dd class="ui-dlist-det">{{agentStateStr agentState}}</dd>

              <dt class="ui-dlist-tit">不批准理由：</dt>
              <dd class="ui-dlist-det"><input type="text" name="reason" id="reason" ></dd>
            </dl>
          </div>
          <a href="javascript:;" class="ui-button ui-button-lorange" onclick="approveDrawBrokerage({{id}})">通过</a> <a href="javascript:;" class="ui-button ui-button-lwhite" onclick="refuseDrawBrokerage({{id}})">拒绝</a> </div>
      </div>
    </div>
  </div> 
   {{/each}}
</script>
<script type="text/javascript">

var page = 1,rows=20,totalPage;
Handlebars.registerHelper('trClass',function(index,options){
    if(index%2==0){
        return 'class="ui-table-split"';
    }else{
        return '';
    }
});
Handlebars.registerHelper('agentStateStr',function(agentState,options){
    if(agentState==0){
        return '审核中';
    }
    if(agentState==1){
        return '审核通过';
    }
    if(agentState==-1){
        return '审核不通过';
    }
});
$(function() {

    //加载用户评论
    show(1);
});
var agentUserList=Handlebars.compile($('#agentUserList').html());
function show(pageNo){
    page=pageNo;
    var agentState = null; 
    $.ajax({ 
        url: '${ctx}/ht/getAgentUserList',
        type: 'POST',
        data: {agentState:agentState,page:page,rows:rows},
        cache:false,
        dataType:'json',  
        success: function(data){  
            $('#tableData').html(agentUserList(data.rows));
            $('#paging').html(pageFoot(page,data.total,20));
         },
        error : function(data) {    
            alert(data);
        }    
    });
}


var agentUserWin=Handlebars.compile($('#agentUserInfo').html());
function openWin(agentId){
	   $.ajax({ 
	        url: '${ctx}/ht/getAgentUserList',
	        type: 'POST',
	        data: {agentId:agentId,page:1,rows:1},
	        cache:false,
	        dataType:'json',  
	        success: function(data){ 
	            $('#open-window').html(agentUserWin(data.rows)); 
	            $('.idCardImg').on('click',function(){
	                var _this = $(this);
	                imgShow("#outerdiv", "#innerdiv", "#bigimg", _this);
	            });
	         },
	        error : function(data) {    
	            alert(data);
	        }    
	    });
	
}
function closeWin(){
	  $('#open-window').html(''); 
}

function approveDrawBrokerage(agentId){
    $.ajax({ 
        url: '${ctx}/ht/approveAgent',
        type: 'POST',
        data: {id:agentId,agentState:1},
        cache:false,
        dataType:'json',  
        success: function(data){
        	if(data.success){
        		$('#open-window').html('');	
        		show(page);
        	}else{
        		alert('提交失败，错误原因:'+data.msg);
        	}
         },
        error : function(data) {    
            alert(data);
        }    
    });
}
function refuseDrawBrokerage(agentId){
    var reason=$('#reason').val();
    if(reason.length == 0){
        alert('请输入不批准理由');
        return;
    }
    $.ajax({ 
        url: '${ctx}/ht/approveAgent',
        type: 'POST',
        data: {id:agentId,agentState:-1,reason:reason},
        cache:false,
        dataType:'json',  
        success: function(data){
            if(data.success){
                $('#open-window').html(''); 
                show(page);
            }else{
                alert('提交失败，错误原因:'+data.msg);
            }
         },
        error : function(data) {    
            alert(data);
        }    
    });
}
</script>




</body>
</html>
